package cn.iocoder.yudao.module.resource.dal.mysql.message;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.resource.controller.admin.message.vo.MessagePageReqVO;
import cn.iocoder.yudao.module.resource.dal.dataobject.message.MessageDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 对话 Mapper
 *
 * @author lizhongwen
 */
@Mapper
public interface MessageMapper extends BaseMapperX<MessageDO> {

    default PageResult<MessageDO> selectPage(MessagePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MessageDO>()
                .eqIfPresent(MessageDO::getUserId, reqVO.getUserId())
                .likeIfPresent(MessageDO::getUserText, reqVO.getUserText())
                .likeIfPresent(MessageDO::getReplyText, reqVO.getReplyText())
                .eqIfPresent(MessageDO::getGameMatchId, reqVO.getGameMatchId())
                .eqIfPresent(MessageDO::getWsSessionId, reqVO.getWsSessionId())
                .eqIfPresent(MessageDO::getTraceId, reqVO.getTraceId())
                .eqIfPresent(MessageDO::getSenderType, reqVO.getSenderType())
                .eqIfPresent(MessageDO::getContentType, reqVO.getContentType())
                .betweenIfPresent(MessageDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MessageDO::getMessageId));
    }

    default PageResult<MessageDO> getMessagePageByUserId(Long userId, MessagePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MessageDO>()
                .eqIfPresent(MessageDO::getUserId, userId)
                .likeIfPresent(MessageDO::getUserText, reqVO.getUserText())
                .likeIfPresent(MessageDO::getReplyText, reqVO.getReplyText())
                .eqIfPresent(MessageDO::getGameMatchId, reqVO.getGameMatchId())
                .eqIfPresent(MessageDO::getWsSessionId, reqVO.getWsSessionId())
                .eqIfPresent(MessageDO::getTraceId, reqVO.getTraceId())
                .eqIfPresent(MessageDO::getSenderType, reqVO.getSenderType())
                .eqIfPresent(MessageDO::getContentType, reqVO.getContentType())
                .betweenIfPresent(MessageDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MessageDO::getMessageId));
    }

}